﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace LpbPrj.Client.Tools.Converter
{
    public class DoubleStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return null;

            string output = null;

            {
                if (value is double input)
                {
                    if (parameter == null)
                    {
                        output = input.ToDouble().ToShowString();
                    }

                    else
                    {
                        int digits = System.Convert.ToInt32(parameter);
                        output = input.ToDouble().ToShowString(digits);
                    }

                }
            }

            {
                if (value is decimal input)
                {
                    if (parameter == null)
                    {
                        output = System.Convert.ToDouble(input).ToDouble().ToShowString();
                    }

                    if (parameter != null && parameter is int digits)
                    {
                        output = System.Convert.ToDouble(input).ToDouble().ToShowString(digits);
                    }
                }
            }

            return output;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }


}
